package com.yunshang.ys.utils;

import android.content.Context;
import android.content.SharedPreferences;

import com.yunshang.ys.base.BaseApplication;

public class UserInfo {


    private static final String TABLE_NAME = "UserInfo";
    private static final String TOKEN = "token";
    private static final String ACCOUNT = "acshare";
    private static final String ACCOUNTCHECK = "acshareck";
    private static final String PASSWORD = "pwshare";
    private static final String PASSWORDCHECK = "pwshareck";
    private static final String HAS_LOGIN = "hasLogin";
    private static final String ROLE_ID = "roleId";
    private static final String COMPANY_STATUS = "companyStatus";
    private static final String MY_HUANXIN_ID = "myHuanxinId";
    private static final String MY_NICKNAME = "myNickname";
    private static final String MY_LOGO = "myLogo";


    public static void setAccountCH(boolean token){
        SharedPreferences sharedPreferences = BaseApplication.getAppContext()
                .getSharedPreferences(TABLE_NAME, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putBoolean(ACCOUNTCHECK,token);
        editor.commit();
    }

    public static boolean getAccountCH(){
        SharedPreferences sharedPreferences = BaseApplication.getAppContext()
                .getSharedPreferences(TABLE_NAME, Context.MODE_PRIVATE);
        return sharedPreferences.getBoolean(ACCOUNTCHECK,false);
    }

    public static void setPasswordCH(boolean token){
        SharedPreferences sharedPreferences = BaseApplication.getAppContext()
                .getSharedPreferences(TABLE_NAME, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putBoolean(PASSWORDCHECK,token);
        editor.commit();
    }

    public static boolean getPasswordCH(){
        SharedPreferences sharedPreferences = BaseApplication.getAppContext()
                .getSharedPreferences(TABLE_NAME, Context.MODE_PRIVATE);
        return sharedPreferences.getBoolean(PASSWORDCHECK,false);
    }


    public static void setPassword(String token){
        SharedPreferences sharedPreferences = BaseApplication.getAppContext()
                .getSharedPreferences(TABLE_NAME, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putString(PASSWORD,token);
        editor.commit();
    }

    public static String getPassword(){
        SharedPreferences sharedPreferences = BaseApplication.getAppContext()
                .getSharedPreferences(TABLE_NAME, Context.MODE_PRIVATE);
        return sharedPreferences.getString(PASSWORD,"");
    }

    public static void setAccount(String token){
        SharedPreferences sharedPreferences = BaseApplication.getAppContext()
                .getSharedPreferences(TABLE_NAME, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putString(ACCOUNT,token);
        editor.commit();
    }
    public static String getAccount(){
        SharedPreferences sharedPreferences = BaseApplication.getAppContext()
                .getSharedPreferences(TABLE_NAME, Context.MODE_PRIVATE);
        return sharedPreferences.getString(ACCOUNT,"");
    }

    public static void setToken(String token){
        SharedPreferences sharedPreferences = BaseApplication.getAppContext()
                .getSharedPreferences(TABLE_NAME, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putString(TOKEN,token);
        editor.commit();
    }

    public static void setHasLogin(Boolean hasLogin){
        SharedPreferences sharedPreferences = BaseApplication.getAppContext()
                .getSharedPreferences(TABLE_NAME, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putBoolean(HAS_LOGIN,hasLogin);
        editor.commit();
    }

    /**
     * 0是游客登录, 1是个人普通用户，2是企业用户，3是个人第三方登录用户,4为个人用户未完善资料
     * @param roleId
     */
    public static void setRoleId(String roleId){
        SharedPreferences sharedPreferences = BaseApplication.getAppContext()
                .getSharedPreferences(TABLE_NAME, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putString(ROLE_ID,roleId);
        editor.commit();
    }

    public static String getToken(){
        SharedPreferences sharedPreferences = BaseApplication.getAppContext()
                .getSharedPreferences(TABLE_NAME, Context.MODE_PRIVATE);
        return sharedPreferences.getString(TOKEN,"");
    }

    public static boolean getHasLogin(){
        SharedPreferences sharedPreferences = BaseApplication.getAppContext()
                .getSharedPreferences(TABLE_NAME, Context.MODE_PRIVATE);
        return sharedPreferences.getBoolean(HAS_LOGIN,false);
    }

    public static String getRoleId(){
        SharedPreferences sharedPreferences = BaseApplication.getAppContext()
                .getSharedPreferences(TABLE_NAME, Context.MODE_PRIVATE);
        return sharedPreferences.getString(ROLE_ID,"");
    }

    public static void setCompanyStatus(boolean companyStatus){
        SharedPreferences sharedPreferences = BaseApplication.getAppContext()
                .getSharedPreferences(TABLE_NAME, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putBoolean(COMPANY_STATUS,companyStatus);
        editor.commit();
    }

    /**
     * true是审核通过
     * false是审核中
     * @return
     */
    public static boolean getCompanyStatus(){
        SharedPreferences sharedPreferences = BaseApplication.getAppContext()
                .getSharedPreferences(TABLE_NAME, Context.MODE_PRIVATE);
        return sharedPreferences.getBoolean(COMPANY_STATUS,false);
    }

    public static void setMyHuanxinId(String id){
        SharedPreferences sharedPreferences = BaseApplication.getAppContext()
                .getSharedPreferences(TABLE_NAME, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putString(MY_HUANXIN_ID,id);
        editor.commit();
    }

    public static String getMyHuanxinId(){
        SharedPreferences sharedPreferences = BaseApplication.getAppContext()
                .getSharedPreferences(TABLE_NAME, Context.MODE_PRIVATE);
        return sharedPreferences.getString(MY_HUANXIN_ID,"");
    }

    public static void setMyNickname(String myNickname){
        SharedPreferences sharedPreferences = BaseApplication.getAppContext()
                .getSharedPreferences(TABLE_NAME, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putString(MY_NICKNAME,myNickname);
        editor.commit();
    }

    public static String getMyMyNickname(){
        SharedPreferences sharedPreferences = BaseApplication.getAppContext()
                .getSharedPreferences(TABLE_NAME, Context.MODE_PRIVATE);
        return sharedPreferences.getString(MY_NICKNAME,"");
    }

    public static void setMyLogo(String myLogo){
        SharedPreferences sharedPreferences = BaseApplication.getAppContext()
                .getSharedPreferences(TABLE_NAME, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putString(MY_LOGO,myLogo);

        editor.commit();
    }

    public static String getMyLogo(){
        SharedPreferences sharedPreferences = BaseApplication.getAppContext()
                .getSharedPreferences(TABLE_NAME, Context.MODE_PRIVATE);
        return sharedPreferences.getString(MY_LOGO,"");
    }

}